package com.jackson.javadesignmodel.FactoryAndStrategy.factory;

/*
 * Author: JacksonCoder
 * FileName: DiscountStrategyFactory
 * Version: 1.0.0
 * Date: 2025-09-22
 */

import com.jackson.javadesignmodel.FactoryAndStrategy.enums.UserType;
import com.jackson.javadesignmodel.FactoryAndStrategy.strategy.DiscountStrategy;
import com.jackson.javadesignmodel.FactoryAndStrategy.strategy.impl.NormalStrategy;
import com.jackson.javadesignmodel.FactoryAndStrategy.strategy.impl.SvipStrategy;
import com.jackson.javadesignmodel.FactoryAndStrategy.strategy.impl.VipStrategy;

import java.util.EnumMap;
import java.util.Map;

public class DiscountStrategyFactory {
    // 一个工厂管理所有策略
    private static final Map<UserType, DiscountStrategy> REPO
            = new EnumMap<>(UserType.class);

    static {
        REPO.put(UserType.NORMAL, new NormalStrategy());
        REPO.put(UserType.VIP, new VipStrategy());
        REPO.put(UserType.SVIP, new SvipStrategy());
    }

    public static DiscountStrategy getStrategy(UserType type) {
        DiscountStrategy strategy = REPO.get(type);
        if (strategy == null) {
            throw new IllegalArgumentException("No strategy for " + type);
        }
        return strategy;
    }

}
